package com.xlf.common.auth.authentication.JwtAuthentication;

import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

/**
 * 配置拦截所有请求
 * @author xlf
 */
public class JwtAuthenticationConfigurer  extends AbstractHttpConfigurer<JwtAuthenticationConfigurer, HttpSecurity> {


    @Override
    public void configure(HttpSecurity builder) throws Exception {


        AuthenticationManager localAuthManager = builder.getSharedObject(AuthenticationManager.class);

        JwtAuthenticationFilter filter = new JwtAuthenticationFilter(localAuthManager);

        //
        builder.authenticationProvider(new JwtAuthenticationProvider())
                .addFilterBefore(filter, UsernamePasswordAuthenticationFilter.class);
    }
}
